package com.example.lirisheng.springbootfinalexperiment.controller;

import com.example.lirisheng.springbootfinalexperiment.service.ResService;
import com.example.lirisheng.springbootfinalexperiment.util.RespBean;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.web.DefaultRedirectStrategy;
import org.springframework.stereotype.Controller;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 *  在springboot的自动配置中有个controller类{@BasicErrorController},mapping 到"/error"中
 *  所以可以看出,该类就是处理程序中的/error情况的
 *  但如果我们要自定义mapping到/error,应该怎么做呢
 *  做法:即编写一个controller类,实现接口{@org.springframework.boot.web.servlet.error.ErrorController},就可以啦
 *  原理:推测就是如果在项目启动的时候,如果检查到容器中有实现接口{@org.springframework.boot.web.servlet.error.ErrorController}的bean
 *       ,就不会执行该类{@BasicErrorController}自动配置,没有,则把该类{@BasicErrorController}注入容器中
 *
 *
 *       问题:为什么zhege
 */
@RestController
public class PublicController implements org.springframework.boot.web.servlet.error.ErrorController {

    public final Log logger = LogFactory.getLog(AdminController.class);

    @Autowired
    ResService resService;

    @Override
    public String getErrorPath() {
        return null;
    }

    @ApiOperation(value = "接收系统异常", notes = "系统出现错误,都会转发到该路径")
    @RequestMapping("/error")
    public RespBean error(HttpServletRequest request, HttpServletResponse response){
        if(logger.isDebugEnabled()){
            logger.debug("进入error");
        }

        return RespBean.error("不知名错误,抛出异常");
    }


}
